/*
 * @Descripttion: 
 * @version: 
 * @Author: turingchang
 * @Date: 2020-12-23 09:36:50
 * @LastEditors: turingchang
 * @LastEditTime: 2020-12-23 17:54:09
 */

'use strict';

module.exports = app => {
  // const {
  //   STRING,
  //   INTEGER,
  //   DATE,
  //   DATEONLY,
  //   sequelize
  // } = app.Sequelize;

  const sequelize = app.Sequelize;

  const Model = app.model.define(
    'job_log', {
      id: {
        type: sequelize.INTEGER(11),
        primaryKey: true,
        autoIncrement: true
      },
      uuid:{
        type: sequelize.STRING(200),
        allowNull: false,
      },
      job_id:{
        type: sequelize.INTEGER(11),
        allowNull: false,
        defaultValue:0,
      },
      response_result:{
        type: sequelize.STRING(200),
        allowNull: true,
        defaultValue:'',
      },
      response_success:{
        type: sequelize.INTEGER(11),
        allowNull: true,
        defaultValue:0,
      },
      tag:{
        type: sequelize.STRING(200),
        allowNull: true,
        defaultValue:'',
      },
      create_time: {
        type:sequelize.DATE,
        defaultValue:sequelize.now,
        get() {
          let t = this.getDataValue('create_time');
          t = t ? app.utils.time.moment(t).format('YYYY-MM-DD HH:mm:ss') :'';
          return t ;
        }
      },
      update_time: {
        type: sequelize.DATE,
        defaultValue:sequelize.now,
        get() {
          let t = this.getDataValue('update_time');
          t = t ? app.utils.time.moment(t).format('YYYY-MM-DD HH:mm:ss') :'';
          return t ;
        }
      },
      delete_time: {
        type: sequelize.DATE,
        defaultValue:null,
        get() {
          let t = this.getDataValue('delete_time');
          t = t ? app.utils.time.moment(t).format('YYYY-MM-DD HH:mm:ss') :'';
          return t ;
        }
      },
    },
    {
      tableName: 'job_log', //自定义映射数据库真实表名
      timestamps:false,
      // freezeTableName: true,  //强制表名等于模型名
    },
  );

  return Model;
};